package com.superatom.concurrent.basic.sleep;

import com.superatom.concurrent.basic.LiftOff;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 使线程进入睡眠状态
 * 是影响任务行为的一种简单方法
 */
public class SleepingTask extends LiftOff{
    public void run(){
        while (countDown-- > 0){
            System.out.print(status());
            try {
                TimeUnit.MILLISECONDS.sleep(180);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args){
        ExecutorService exec = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++){
            exec.execute(new SleepingTask());
        }
        exec.shutdown();
    }
}
